package com.stylefeng.guns.modular.contractmanager.controller;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.stylefeng.guns.core.base.controller.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.beans.factory.annotation.Autowired;
import com.stylefeng.guns.core.log.LogObjectHolder;
import org.springframework.web.bind.annotation.RequestParam;
import com.stylefeng.guns.modular.system.model.ContractInfo;
import com.stylefeng.guns.modular.contractmanager.service.IContractInfoService;

/**
 * 合同基本信息控制器
 *
 * @author LiuXin
 * @Date 2018-11-14 10:34:55
 */
@Controller
@RequestMapping("/contractInfo")
public class ContractInfoController extends BaseController {

    private String PREFIX = "/contractmanager/contractInfo/";

    @Autowired
    private IContractInfoService contractInfoService;

    /**
     * 跳转到合同基本信息首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "contractInfo.html";
    }

    /**
     * 跳转到添加合同基本信息
     */
    @RequestMapping("/contractInfo_add")
    public String contractInfoAdd() {
        return PREFIX + "contractInfo_add.html";
    }

    /**
     * 跳转到修改合同基本信息
     */
    @RequestMapping("/contractInfo_update/{contractInfoId}")
    public String contractInfoUpdate(@PathVariable Integer contractInfoId, Model model) {
        ContractInfo contractInfo = contractInfoService.selectById(contractInfoId);
        model.addAttribute("item",contractInfo);
        LogObjectHolder.me().set(contractInfo);
        return PREFIX + "contractInfo_edit.html";
    }

    /**
     * 获取合同基本信息列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
        EntityWrapper<ContractInfo> entityWrapper = new EntityWrapper<>();
        return contractInfoService.selectList(null);
    }

    /**
     * 新增合同基本信息
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(ContractInfo contractInfo) {
        contractInfoService.insert(contractInfo);
        return SUCCESS_TIP;
    }

    /**
     * 删除合同基本信息
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer contractInfoId) {
        contractInfoService.deleteById(contractInfoId);
        return SUCCESS_TIP;
    }

    /**
     * 修改合同基本信息
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(ContractInfo contractInfo) {
        contractInfoService.updateById(contractInfo);
        return SUCCESS_TIP;
    }

    /**
     * 合同基本信息详情
     */
    @RequestMapping(value = "/detail/{contractInfoId}")
    @ResponseBody
    public Object detail(@PathVariable("contractInfoId") Integer contractInfoId) {
        return contractInfoService.selectById(contractInfoId);
    }
}
